package com.java2207.group1.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.java2207.group1.bo.DrugStorageBo;
import com.java2207.group1.pojo.Cases;
import com.java2207.group1.pojo.DrugStorage;
import com.java2207.group1.service.DrugStorageService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * Lenovo 2022/7/27 15:38
 */
@Component
@Scope("prototype")    //设置成多例模式
public class DrugStorageListener extends AnalysisEventListener<DrugStorageBo> {

    @Autowired
    DrugStorageService drugStorageService;

    @Override
    public void invoke(DrugStorageBo data, AnalysisContext analysisContext) {

        System.out.println(data);
        DrugStorage drug = new DrugStorage();

        //属性拷贝  将data的属性值复制给case
        BeanUtils.copyProperties(data,drug);
        drugStorageService.addDrug(drug);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
